<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/aui.css">
    <link rel="stylesheet" href="css/style.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="js/init.js"></script>
    <title>项目详情</title>
</head>
<body>
<header>
    <a href="javascript:history.back(-1)" class="f1 head-back"></a>
    <div class="f8">项目详情</div>
    <div class="f1"></div>
</header>
<section class="bg-gray">
    <div class="pad-3">
        <ul class="zhongchoulist bg-white border-radius-1 border-gray hidden ">
            <li>
                <span >状态</span>
                <p id="status">等待中</p>
            </li>
            <li >
                <span >币种</span>
                <p id="btext">无</p>
            </li>
            <li >
                <span >开始时间</span>
                <p id="opentime">0000-00-00</p>
            </li>
            <li>
                <span>结束时间</span>
                <p id="overtime">0000-00-00</p>
            </li>
            <li>
                <span >收益率</span>
                <p id="sy">15%</p>
            </li>
            <li>
                <span >最小认购数量</span>
                <p id="min">0</p>
            </li>
            <li>
                <span >最大认购数量</span>
                <p id="max">0</p>
            </li>
            <li >
                <span >认购进度</span>
                <p id="jindu">0%</p>
            </li>
            <li>
                <span>众筹数量</span>
                <p id="permoney">0</p>
            </li>
        </ul>

        <div id="gojoin" class="pad-2-3 bg-orange color-white center border-radius-1 mar-t-5 none">我要参与</div>
    </div>

</section>

<!--抢购弹窗-->
<div class="mask none"></div>
<div id="joinbox" class="mask-box bg-white border-radius-1 hidden none">
    <p class="pad-2 bg-blue right">
        <span class="fl color-white">我要参与</span>
        <span class="close" ></span>
    </p>
    <div class="pad-3-5">
        <p class="pad-b-2">
            我的总数量：
            <span id="mynum"></span>
        </p>
        <input id="num" class="col-10 pad-2-3 border-gray mar-b-2" type="number" placeholder="请输入参与数量" onfocus="inputFocus(this)">
        <input id="password_2" class="col-10 pad-2-3 border-gray mar-b-2" type="password" placeholder="请输入二级密码" onfocus="inputFocus(this)">
        <div class="col-3 auto line-h-2 bg-blue border-radius-1 center color-white" onclick="tijiao()">确定</div>
    </div>
</div>


<script src="js/foot.js"></script>
<script>
    var periods_id = getQueryString('periods_id');
    var isbuy = getQueryString('isbuy');
    isbuy == 1?$("#gojoin").show():$("#gojoin").hide();

    var data = {};
    data.userid = localStorage.user_id;
    data.token = localStorage.token;
    data.periods_id = periods_id;

    // 参与抢购
    $("#gojoin").click(function () {
        new AjaxRequest({
            type: 'post',
            data: data,
            dataType: 'json',
            url: hostUrl + 'index/Crowdfound/getusemoney',
            callback: res => {
                if(res.status == 1){
                    $("#mynum").text(res.data?res.data:'0');
                }
            }
        });
        $(".mask").show();
        $("#joinbox").show();
    });
    var lock;
    function tijiao() {
        if(!lock){
            lock = true;
            var num = $("#num").val();
            var password_2 = $("#password_2").val();
            if(!num || !password_2){
                toast('请输入完整信息');
                return;
            }
            data.money = num;
            data.password_2 = password_2;
            new AjaxRequest({
                type: 'post',
                data: data,
                dataType: 'json',
                url: hostUrl + 'index/Crowdfound/snap_up',
                callback: res => {
                    toast(res.msg);
                    if(res.status == 1){
                        setTimeout(function () {
                            close();
                            location.href = 'myItem.html';
                        },2000)
                    }else{
                        lock = false;
                    }
                },
                error: err => {
                    lock = false;
                }
            })
        }

    };

    // 获取页面数据
    var data = {
        userid: localStorage.user_id,
        token: localStorage.token,
        periods_id: periods_id,
    };
    new AjaxRequest({
        type: 'post',
        data: data,
        dataType: 'json',
        url: hostUrl + 'index/Crowdfound/detailed',
        callback: res => {

            if(res.status == 1){
                $("#status").text(res.status == 1?'等待中':res.status == 2?'进行中':res.status == 3?'已完成':res.status == 4?'崩盘':res.status == 5?'销毁':res.status == 6?'已结束':'默认')

                $("#btext").text(res.data.coin_type==1?'以太坊（ETH）':res.data.coin_type==2?'以太经典（ETC）':'无');
                $("#opentime").text(transtime(res.data.open_time));
                $("#overtime").text(transtime(res.data.over_time));
                $("#max").text(res.data.offer_max);
                $("#min").text(res.data.offer_min);
                $("#jindu").text(res.data.bl+'%');
                $("#permoney").text(res.data.permoney);

            }
        }
    });

    // 时间戳转换
    function transtime(time) {
        var t = new Date();
        t.setTime(time*1000);
        var end = t.getFullYear() +'-'+ ((t.getMonth()+1)<10?'0'+(t.getMonth()+1):t.getMonth()+1) +'-'+ (t.getDate()<10?'0'+t.getDate():t.getDate()) + ' '+ (t.getHours()<10?'0'+t.getHours():t.getHours()) +':'+ (t.getMinutes()<10?'0'+t.getMinutes():t.getMinutes()) +':'+ (t.getSeconds()<10?'0'+t.getSeconds():t.getSeconds());
        return end;
    }

    function inputFocus(e) {
        var num = document.getElementById('num');
        var pwd = document.getElementById('password_2');

        let u = navigator.userAgent, app = navigator.appVersion;
        let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
        if(isAndroid){
            setTimeout(function() {
                num.scrollIntoViewIfNeeded();
                num.scrollIntoView();

                pwd.scrollIntoViewIfNeeded();
                pwd.scrollIntoView();

            }, 500);
        }
    }

</script>
</body>
</html>